package com.lims.algorithm.algset;

import java.util.Scanner;

public class Recursive {
    public static int times = 1;

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        System.out.println("输入可乐瓶数：");
        int i = in.nextInt();
        int times = 1;
        int j = fun(i);
        System.out.println("=====" + i + "个瓶盖最终共兑换" + j + "个可乐");
    }

    public static int fun(int i) {
        if (i < 3) {
            System.out.println("数量少于3,兑换不了");
            return i;
        } else {
            System.out.println("第" + (times++) + "次兑换，" + "共有:" +
                    i + "个瓶盖，用" + (i - i % 3) + "个瓶盖本次兑换了:" +
                    (i / 3) + "个新可乐。剩余" + (i % 3) + "个用于下次兑换");
            return ((i - i % 3) + fun(i / 3 + i % 3));
        }
    }
}
